﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// Point d'entrée principal de l'application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            double v = Quality(341);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 ff = new Form1();
            ff.Show();
            //6:05 /10:19
            DateTime start = DateTime.Today.AddHours(double.Parse(System.Configuration.ConfigurationManager.AppSettings["RLHour"])).AddMinutes(double.Parse(System.Configuration.ConfigurationManager.AppSettings["RLMin"]));
            DateTime EtStart = DateTime.Today.AddHours(double.Parse(System.Configuration.ConfigurationManager.AppSettings["ETHour"])).AddMinutes(double.Parse(System.Configuration.ConfigurationManager.AppSettings["ETMin"]));
            DateTime tmp;
            int LastPlayed = -1;
            int[] HoursToTime = System.Configuration.ConfigurationManager.AppSettings["Hours"].Split(';').Select(p => int.Parse(p)).ToArray();
            while (ff.Visible)
            {
                Application.DoEvents();
                System.Threading.Thread.Sleep(60);
                tmp = EtStart.AddMinutes(DateTime.Now.Subtract(start).TotalMinutes * 20.57);
                ff.label1.Text = tmp.ToShortTimeString();
                if ( (HoursToTime.Contains(tmp.Hour) || HoursToTime.Contains(tmp.Hour + 2))&& LastPlayed != tmp.Hour)
                {
                    Stream str = Properties.Resources.Windows_Ding;
                    SoundPlayer snd = new SoundPlayer(str);
                    snd.Play();
                    LastPlayed = tmp.Hour;
                }
            }

        }
        static double Quality(double x)
        {
            return 3.4275521095175201e+001 * Math.Pow(x, 0)
                 + 3.4958806693020045e-001 * Math.Pow(x, 1)
                 + 3.5279187952857053e-005 * Math.Pow(x, 2);
        }

    }
}
